package com.rssreader.client.portlets;

import java.util.List;

import com.extjs.gxt.ui.client.dnd.DND;
import com.extjs.gxt.ui.client.dnd.DropTarget;
import com.extjs.gxt.ui.client.event.DNDEvent;
import com.extjs.gxt.ui.client.mvc.Dispatcher;
import com.extjs.gxt.ui.client.widget.custom.Portlet;
import com.extjs.gxt.ui.client.widget.layout.FitLayout;
import com.rssreader.client.RSSReaderConstants;
import com.rssreader.client.components.ItemPanel;
import com.rssreader.client.mvc.events.AppEvents;
import com.rssreader.shared.model.Item;

public class ItemPortlet extends Portlet {

    private final ItemPanel itemPanel = new ItemPanel();

    public ItemPortlet() {
	setHeading("Item");
	setLayout(new FitLayout());
	setHeight(250);
	setId(RSSReaderConstants.ITEM_PORTLET);

	itemPanel.setHeaderVisible(false);
	add(itemPanel);
	Dispatcher.forwardEvent(AppEvents.NewPortletCreated, this);

	DropTarget target = new DropTarget(this) {
	    @Override
	    protected void onDragDrop(DNDEvent event) {
		super.onDragDrop(event);
		List<Item> items = event.getData();
		itemPanel.displayItem(items.get(0));
	    }
	};
	target.setOperation(DND.Operation.COPY);
	target.setGroup(RSSReaderConstants.ITEM_DD_GROUP);
    }
}
